/**
 * Created by tianjie on 2017/11/28.
 */
$(function () {
    initPage();
})

var param = param;
var roomId = param.split(",")[1];
var date = param.split(",")[0];
var beginTime = date.substr(0,10);
var endTime = date.substr(13);
var data = {
    "roomId":roomId,
    "beginTime":beginTime,
    "endTime":endTime
}

function initPage() {
    $("#roomId").html("房间ID:" + roomId);
    $.ajax({
        url:"/admin/statistics/PlayGameRoomData?random="+Math.random(),
        type:'POST', //GET
        async:false,    //或false,是否异步
        data: data,
        dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
        success:function(data,textStatus,jqXHR){
            console.log(data);
            if(data.code == 0){
                $("#demo-table").html("");
                var str = "<thead><tr><th>排名</th><th>角色ID</th><th>角色名称</th><th>局数</th><th>得分</th>" +
                    "</tr></thead>";
                if(data.data.length > 0){
                    $("#roomBeginTime").html("房间开始时间:" + data.data[0].roomBeginTime);
                    $("#roomEndTime").html("房间结束时间:" + data.data[0].roomEndTime);
                    $.each(data.data, function (i, n) {
                        str += "<tr><td>"+(i+1)+"</td><td>"+n.roleUid+"</td><td>"+n.roleName+"</td><td>"
                            +n.totalRound+"</td><td>"+n.totalScore+"</td></tr>";
                    });
                }else {
                    str += "<tr><td colspan='5'>没有找到匹配的记录</td></tr>"
                }
                $("#demo-table").append(str);
            }else {
                alert(data.msg);
            }
        },
        error:function(xhr,textStatus){
            console.log('错误')
            console.log(xhr)
            console.log(textStatus)
        }
    })
}